package aaaBlogger.img;

import java.util.Map;
import java.util.Set;

import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;

import com.attilax.core;
import com.attilax.cmsPoster.BlogPubberAbs;
import com.attilax.cmsPoster.BlogPubberMainform;
import com.attilax.cmsPoster.Ipub;
import com.attilax.formH5.EncodeX;
import com.attilax.io.filex;
import com.attilax.io.pathx;
import com.attilax.text.strUtil;
import com.attilax.util.PropX;


/**
 * aaaBlogger.img.discuzxPubber
 * @author Administrator
 *
 */
public class discuzxPubber  extends BlogPubberAbs implements Ipub,Ipub2{

	public static void main(String[] args) {
		Map puber = (Map) core.newx(("aaaBlogger.img.SohuPubber"));
		
	}
	@Override
	public void pub2(String p1tit, String context, FirefoxDriver driver) {
		
//		String t = getAuthorTxt("sohu");
//		context=context.replace("$attilax_blog$", t);
				
				
				
		   driver.findElement(By.id("subject")).clear();
		    driver.findElement(By.id("subject")).sendKeys(p1tit);
		 //   driver.findElement(By.id("save")).click();
		    
		    
		  //--------------context 
		//	context = changeBlogLink(context);
			context = EncodeX.jsEncodeSingleQuoue(context);
			
			// p2_txt="test in html";
			String baseDir=pathx.classPathParent_jensyegeor()
					 + "/blogInfoTable/mrhzp_pub.js";
			String js =filex.read(baseDir );
			String script = js.replace("@txt", context);

			// window.document.getElementById('editor').value='..xxx'
			driver.executeScript(script,
					driver.findElement(By.id("subject")));
		
	}

	@Override
	public void login(FirefoxDriver driver, Object px) {
		try {
			 driver.findElement(By.linkText("登录")).click();
		} catch (Exception e) {
			// TODO: handle exception
		}
	   
 Map m=(Map) px;
	    driver.findElement(By.id("ls_username")).clear();
	    driver.findElement(By.id("ls_username")).sendKeys(m.get("user").toString());
	    driver.findElement(By.name("password")).clear();
	    //ls_password
	    driver.findElement(By.name("password")).sendKeys(m.get("pwd").toString());
	 //   driver.findElement(By.id("login_toolbar")).click();
	    driver.findElement( By.cssSelector("button.pn")).click();
	//    driver.findElement(By.cssSelector("div.entriesAdd > a")).click();
		
	}
	
	
	  public boolean isInLoginForm(String title, String sou) {
		  
		  if(title.contains("提示信息"))
			  return true;
		if(sou.contains(("自动登录")))
		return true;
		else
			return false;
//		PropX px=(PropX) propMap.get(blogName.get());
//		String loginFormStr =px.getProperty("loginFormStr");
//		
//		//if (title.equals(loginFormStr))
//		Set<String> set=strUtil.toSet(loginFormStr.trim());
//		if(set.contains(title))
//			return true;
//		return false;
	}


}
